package org.example.footshoppingmaster.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

import org.example.footshoppingmaster.custom.ResultVO;
import org.example.footshoppingmaster.pojo.DO.Product;
import org.example.footshoppingmaster.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品Api")
@RestController
@CrossOrigin(origins = "http://127.0.0.1:5173")
@Slf4j
@RequestMapping("/goods")
public class ProductController {

    @Autowired
    private ProductService productServiceImpl;
    /*
    * 根据商品type：man women chile
    *        brand：Nike 彪马
    * 来查询商品
    * */
    @Operation(summary = "查询商品列表")
    @GetMapping("/list")
    public ResultVO<?> selectGoods(@Parameter(name = "type", description = "类型")  @RequestParam String type ,
                                   @Parameter(name = "brand", description = "品牌") @RequestParam(required = false) String brand,
                                   @Parameter(name = "page", description = "页数")  @RequestParam(defaultValue = "1") Integer page,
                                   @Parameter(name = "pageSize", description = "页面大小")  @RequestParam(defaultValue = "8") Integer pageSize){
        return ResultVO.success("获取商品数据成功", productServiceImpl.selectGoods(type,brand,page,pageSize));
    }
    /*
     * 查询商品总数
     * */
    @Operation(summary = "查询商品总数")
    @GetMapping("/lisSum")
    public ResultVO<?> selectGoodsSum(@Parameter(name = "type", description = "类型")  @RequestParam String type ,
                                            @Parameter(name = "brand", description = "品牌") @RequestParam(required = false) String brand){
        return ResultVO.success("获取商品总数成功", productServiceImpl.selectGoodsSum(type,brand));
    }
     /*
     * 根据商品id来查询
     * */
    @Operation(summary = "查询商品详情")
    @GetMapping("/detail")
    public ResultVO<Product> selectGood(@Parameter(name = "id", description = "商品id") @RequestParam Integer id){
        return ResultVO.success("成功获取商品详情",productServiceImpl.selectGoodById(id));
        }

    /*
     * 根据商品id数组来查询商品列表
     * */
    @Operation(summary = "根据数组查询商品列表")
    @PostMapping("/ArrayList")
    public ResultVO<?> selectGoodsListByArray(@RequestBody List<Integer> ids){
        return  ResultVO.success("商品获取成功",productServiceImpl.selectGoodsByIds(ids));
    }


}
